Last updated: 2015-12-15

Code version: c12bd940df26a36d1f462f2dfa0646e58cc24b19

load("../output/dsc-shrink-files/res.RData")
source("../R/set_plot_colors.R")
library(dplyr)

Attaching package: 'dplyr'

The following objects are masked from 'package:stats':

    filter, lag

The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(ggplot2)

#' @param df dataframe of scores for many methods/scenrios etc
#' @return tall dataframe with columns of scores for each method and the "goldmethod" against which plot is to be made
process_score_for_plotting_against_gold=function(df,PLOTMETHODS=c("ash.n","ash.u","ash.hu"),
                                                 GOLDMETHOD="bayes",PLOTSEEDS=1:100,
                                                 PLOTSCENARIOS=c("spiky","near-normal","flat-top","skew","big-normal","bimodal"),
                                                 PLOTNAMES=PLOTSCENARIOS){
  df %<>% filter(seed %in% PLOTSEEDS) %>% filter(scenario %in% PLOTSCENARIOS) %>% filter(method %in% c(PLOTMETHODS,GOLDMETHOD))
  df$scenario = factor(df$scenario,levels=PLOTSCENARIOS)
  levels(df$scenario)= PLOTNAMES
  #create tall version of dataframe
  df %<>% dplyr::select(-user.self,-sys.self,-elapsed,-user.child,-sys.child) %>%
    reshape2::melt(id.vars=c("method","scenario","seed",".id"),value.name="val")
  #separate bayes and remainder
  df.bayes = df %>% filter(method==GOLDMETHOD)
  df.rest = df %>% filter(method!=GOLDMETHOD)

#join bayes with others, so each line has both the bayes and the non-bayes version
  return(inner_join(df.bayes, df.rest, by=c("scenario","seed","variable")))
}


plot_lfsr=function(lfsr,xlab="True lfsr",ylab="Estimated lfsr",xlim=c(0,0.2),ylim=c(0,0.2),legend.position="bottom"){
  p=ggplot(lfsr,
         aes(val.x,val.y,colour=method.y)) +
    facet_grid(. ~ scenario) + 
    guides(alpha=FALSE) +
    geom_abline(colour = "black") +
    geom_abline(colour= "red", slope=2) +
    xlab(xlab) +
    ylab(ylab) +
    geom_point(shape=1,size=0.1,alpha=0.2) 

  p +scale_y_continuous(limits=ylim) +
        scale_x_continuous(limits=xlim)
         
}

lfsr = process_score_for_plotting_against_gold(res$lfsr,PLOTSEEDS=1:100,PLOTMETHODS="ash.n")
lfdr = process_score_for_plotting_against_gold(res$lfdr,PLOTSEEDS=1:100,PLOTMETHODS="ash.n")

p1=plot_lfsr(lfsr,ylim=c(0,1),xlim=c(0,0.2))
p2=plot_lfsr(lfdr,ylim=c(0,1),xlim=c(0,0.2),xlab="True lfdr",ylab="Estimated lfdr")

# cowplot command: plot_grid(p2+theme_gray()+theme(legend.position="none"),p1+theme_gray()+theme(legend.position="none"),nrow=2,align="v")
print(p1+theme(legend.position="none",axis.text.x = element_text(size = 8,angle=45))
      +coord_equal(ratio=1/5) + colScale)
Warning: Removed 95034 rows containing missing values (geom_point).
Warning: Removed 86664 rows containing missing values (geom_point).
Warning: Removed 87526 rows containing missing values (geom_point).
Warning: Removed 81263 rows containing missing values (geom_point).
Warning: Removed 65691 rows containing missing values (geom_point).
Warning: Removed 68258 rows containing missing values (geom_point).

#ggsave("../paper/figures/lfsr_est.pdf",height=3,width=9)
print(p2+theme(legend.position="none",axis.text.x = element_text(size = 8,angle=45))
      +coord_equal(ratio=1/5) + colScale)
Warning: Removed 75034 rows containing missing values (geom_point).
Warning: Removed 73449 rows containing missing values (geom_point).
Warning: Removed 74231 rows containing missing values (geom_point).
Warning: Removed 70760 rows containing missing values (geom_point).
Warning: Removed 62698 rows containing missing values (geom_point).
Warning: Removed 65160 rows containing missing values (geom_point).

#ggsave("../paper/figures/lfdr_est.png",height=3,width=9)
#ggsave("../paper/figures/lfdr_est.pdf",height=3,width=9)
lfsr.s = process_score_for_plotting_against_gold(res$lfsr,PLOTSEEDS=1:100,PLOTMETHODS="ash.n.s")
p1.s=plot_lfsr(lfsr.s,ylim=c(0,1),xlim=c(0,0.2))

print(p1.s+theme(legend.position="none",axis.text.x = element_text(size = 8,angle=45))
      +coord_equal(ratio=1/5))
Warning: Removed 95034 rows containing missing values (geom_point).
Warning: Removed 86664 rows containing missing values (geom_point).
Warning: Removed 87526 rows containing missing values (geom_point).
Warning: Removed 81262 rows containing missing values (geom_point).
Warning: Removed 65690 rows containing missing values (geom_point).
Warning: Removed 68258 rows containing missing values (geom_point).

#ggsave("../paper/figures/lfsr_est_s.png",height=3,width=9)
#ggsave("../paper/figures/lfsr_est_s.pdf",height=3,width=9)
lfsr.s.nn = process_score_for_plotting_against_gold(
    res$lfsr,PLOTSEEDS=1:100,PLOTMETHODS="ash.n.s",
    PLOTSCENARIOS=paste0(c("spiky","near-normal","flat-top","skew","big-normal","bimodal"),"-nn"))
p1.s.nn=plot_lfsr(lfsr.s.nn,ylim=c(0,1),xlim=c(0,0.2))

print(p1.s.nn+theme(legend.position="none",axis.text.x = element_text(size = 8,angle=45))
      +coord_equal(ratio=1/5))
Warning: Removed 80137 rows containing missing values (geom_point).
Warning: Removed 50863 rows containing missing values (geom_point).
Warning: Removed 48567 rows containing missing values (geom_point).
Warning: Removed 40659 rows containing missing values (geom_point).
Warning: Removed 16771 rows containing missing values (geom_point).
Warning: Removed 14071 rows containing missing values (geom_point).

#ggsave("../paper/figures/lfsr_est_s_nn.png",height=3,width=9)

Session information

sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.2 (El Capitan)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] dplyr_0.4.3        ggplot2_1.0.1      RColorBrewer_1.1-2
[4] knitr_1.11        

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.2      magrittr_1.5     MASS_7.3-44      munsell_0.4.2   
 [5] xtable_1.7-4     colorspace_1.2-6 R6_2.1.1         stringr_1.0.0   
 [9] plyr_1.8.3       tools_3.2.3      parallel_3.2.3   grid_3.2.3      
[13] gtable_0.1.2     DBI_0.3.1        dscr_0.1.1       htmltools_0.2.6 
[17] lazyeval_0.1.10  yaml_2.1.13      assertthat_0.1   digest_0.6.8    
[21] shiny_0.12.2     reshape2_1.4.1   formatR_1.2.1    mime_0.4        
[25] evaluate_0.8     rmarkdown_0.8.1  labeling_0.3     stringi_1.0-1   
[29] scales_0.3.0     httpuv_1.3.3     proto_0.3-10